package num242;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 19:33
 * @Desc :
 */
class Solution {
  public boolean isAnagram(String s, String t) {
    if (s == null || t == null || s.length() != t.length()) return false;
    if (s.equals(t)) return true;

    int[] chars = new int[26];
    Arrays.fill(chars, 0);
    for (int i = 0; i < s.length(); i++) {
      chars[s.charAt(i) - 'a']++;
    }
    for (int i = 0; i < t.length(); i++) {
      chars[t.charAt(i) - 'a']--;
    }
    for (int i : chars) {
      if (i != 0) return false;
    }
    return true;
  }

  public static void main(String[] args) {
    String s = "anagram";
    String t = "nagaram";
    System.out.println(new Solution().isAnagram(s, t));
  }
}
